<?php
class omeanalysts_mdl_ome_products extends dbeav_model{

    var $has_export_cnf = true;

    var $export_name = '货品销售情况';

    var $stockcost_enabled = false;

    public function __construct(){
        parent::__construct();
        if(app::get('tgstockcost')->is_installed()){
            $setting_stockcost_cost = app::get("ome")->getConf("tgstockcost.cost");
            if(!$setting_stockcost_cost){
                $this->stockcost_enabled = false;
            }else{
                $this->stockcost_enabled = true;
            }
        }
    }

    public function searchOptions(){
        $columns = array();
        foreach($this->_columns() as $k=>$v){
            if(isset($v['searchtype']) && $v['searchtype']){
                $columns[$k] = $v['label'];
            }
        }

        return $columns;
    }

    public function get_products($filter=null){
        if(isset($filter['time_to']) && $filter['time_to']){
            $filter['time_to'] = $filter['time_to'].' 23:59:59';
        }

        $dayNum = intval((strtotime($filter['time_to'])-strtotime($filter['time_from'])+1)/86400);
        $dayNum = $dayNum ? $dayNum : 1;

        $sql = 'SELECT sum(SI.cost_amount) as cost_amount,sum(SI.nums) as sale_num,sum(SI.sales_amount) as sale_amount,sum(SI.gross_sales) AS gross_sales FROM sdb_ome_sales_items SI LEFT JOIN sdb_ome_sales S ON SI.sale_id = S.sale_id WHERE '.$this->_filter($filter);
        $salestat = $this->db->selectrow($sql);

        $data['sale_amount']      = $salestat['sale_amount'];
        $data['salenums']         = $salestat['sale_num'];
        $data['day_amounts']      = bcdiv($data['sale_amount'], $dayNum,3);
        $data['day_nums']         = bcdiv($data['salenums'], $dayNum,3);

        // 店铺
        $rwhere = '';
        if(isset($filter['shop_id']) && $filter['shop_id']){
            $rwhere .= ' and sa.shop_id =\''.addslashes($filter['shop_id']).'\'';
        }

        $sql = "select sum(sai.num*sai.price) as reship_total_amount,sum(sai.num) as total_reship_num 
                from sdb_sales_aftersale_items sai 
                left join sdb_sales_aftersale sa on sai.aftersale_id = sa.aftersale_id 
                left join sdb_material_basic_material as p on sai.product_id=p.bm_id LEFT JOIN sdb_ome_sales as s ON s.order_id=sa.order_id
                where sai.return_type='return' and s.ship_time >= ".strtotime($filter['time_from'])." and s.ship_time <= ".strtotime($filter['time_to']).$rwhere;
        $reshipstat = $this->db->selectrow($sql);

        $data['reship_nums']      = $reshipstat['total_reship_num'];
        $data['reship_amounts']   = $reshipstat['reship_total_amount'];

        $data['gross_sales']      = $salestat['gross_sales'] - $data['reship_amounts'];
        $data['gross_sales_rate'] = $data['sale_amount'] ? bcdiv($data['gross_sales'], $data['sale_amount'],3) : 0;

        return $data;
    }

    public function count($filter=null){
        if(isset($filter['time_to']) && $filter['time_to']){
            $filter['time_to'] = $filter['time_to'].' 23:59:59';
        }

        $row = $this->db->select('SELECT count(*) as _count FROM (SELECT SI.product_id FROM sdb_ome_sales_items SI LEFT JOIN sdb_ome_sales S ON SI.sale_id = S.sale_id WHERE '.$this->_filter($filter).' GROUP BY SI.bn ) as tb');

        return intval($row[0]['_count']);
    }

    public function getList($cols='*', $filter=array(), $offset=0, $limit=-1, $orderType=null){
        if(isset($filter['time_to']) && $filter['time_to']){
            $filter['time_to'] = $filter['time_to'].' 23:59:59';
        }
        
        $sales_sql = 'SELECT P.material_name,P.type,SI.product_id,SI.cost as aftersale_cost_amount,SI.bn,sum(SI.cost_amount) as cost_amount,sum(SI.nums) as sale_num,sum(SI.sales_amount) as sale_amount,S.order_id,pext.cat_id
                FROM sdb_ome_sales_items SI 
                LEFT JOIN sdb_ome_sales S ON SI.sale_id = S.sale_id 
                LEFT JOIN sdb_material_basic_material AS P ON SI.product_id=P.bm_id
                LEFT JOIN sdb_material_basic_material_ext AS pext ON P.bm_id=pext.bm_id
                WHERE '.$this->_filter($filter);

        if((!$filter['_sale_amount_search'])&&(!$filter['_sale_num_search'])){
            $sales_sql .= ' GROUP BY SI.bn';
        }

        $rows = $this->db->selectLimit($sales_sql,$limit,$offset);
        $goods_type_obj = app::get('ome')->model('goods_type');
        $goods_types = $goods_type_obj->getList('type_id,name', array());
        $types_arr = array();
        foreach($goods_types as $kk => $vv){
            $types_arr[$vv['type_id']] = $vv['name'];
        }

        $dayNum = intval((strtotime($filter['time_to'])-strtotime($filter['time_from'])+1)/86400);
        if($rows){
            foreach($rows as $key=>$val){
                if($rows[$key]['product_id'] ){
                    $rows[$key]['name'] = $val['material_name'];
                    $rows[$key]['type_id'] = ($val['type'] == 1) ? '普通' : '组合';
                }else{
                    $salesMObj = app::get('material')->model('sales_material');
                    $salesMInfo = $salesMObj->getList('sales_material_name,sales_material_type',array('sales_material_bn'=>$val['bn'],'sales_material_type'=>2), 0, 1);
                    if($salesMInfo){
                        $rows[$key]['type_id'] = '促销';
                        $rows[$key]['name'] = $salesMInfo[0]['sales_material_name'];
                    }else{
                        $rows[$key]['type_id'] = '未知';
                    }
                }
                $rows[$key]['day_num'] = $dayNum?round($rows[$key]['sale_num']/$dayNum,2):0;
                $rows[$key]['day_amount'] = $dayNum?strval($rows[$key]['sale_amount']/$dayNum):0;
                $rows[$key]['order_id'] = $rows[$key]['order_id'] ? $rows[$key]['order_id'] : 0;
                $rows[$key]['cat_id'] = $types_arr[$val['cat_id']];

                $sql = "select sum(sai.num*sai.price) as reship_total_amount,sum(sai.num) as total_reship_num from sdb_sales_aftersale_items sai left join sdb_sales_aftersale sa on sai.aftersale_id = sa.aftersale_id  LEFT JOIN sdb_ome_sales as S on S.order_id=sa.order_id where ".$this->rfilter($filter)." and sai.bn = '".addslashes($val['bn'])."'";
    
                $row = $this->db->select($sql);

                $rows[$key]['reship_total_amount'] = $row[0]['reship_total_amount']?$row[0]['reship_total_amount']:0;

                if($this->stockcost_enabled){
                    $aftersale['aftersale_cost_amount'] = $val['aftersale_cost_amount'];//$product_info[$val['bn']]['aftersale_cost_amount'];
                }else{
                    $aftersale['aftersale_cost_amount'] = 0;
                }

                $aftersale['aftersale_cost_amount'] = ($aftersale['aftersale_cost_amount'] * $row[0]['total_reship_num']);
                $rows[$key]['name'] = $rows[$key]['name'];
                $rows[$key]['reship_num'] = intval($row[0]['total_reship_num']);//退货数
                $reship_ratio = $rows[$key]['sale_num']?round($rows[$key]['reship_num']/$rows[$key]['sale_num'],2):0;//退货率
                $rows[$key]['reship_ratio'] = ($reship_ratio*100)."%";
                $rows[$key]['agv_cost_amount'] = round($rows[$key]['cost_amount']/$rows[$key]['sale_num'],2);//平均成本
                $rows[$key]['total_cost_amount'] = round($rows[$key]['cost_amount'] - $aftersale['aftersale_cost_amount'],2);//总成本 = 销售成本-售后商品成本之和
                $rows[$key]['gross_sales'] = $rows[$key]['sale_amount'] - $rows[$key]['reship_total_amount']-$rows[$key]['total_cost_amount'];//销售毛利 = 销售额-退货总额-总成本
                $rows[$key]['agv_gross_sales'] = round($rows[$key]['gross_sales']/$rows[$key]['sale_num'],2);//销售平均毛利 = 销售毛利/销售量
                $gross_sales_rate = ($rows[$key]['sale_amount']>0) ? round($rows[$key]['gross_sales']/$rows[$key]['sale_amount'],2) : 0;//销售毛利率 = 销售毛利/销售额
                $rows[$key]['gross_sales_rate'] = ($gross_sales_rate*100)."%";
                $rows[$key]['sale_price'] = strval($rows[$key]['sale_amount']/$rows[$key]['sale_num']);//销售单价 = 商品销售之和/销售量
            }

             $createtime = time();
             //对数组排序
             if($orderType){
                foreach($rows as $k=>$data){
                    $type_id[$k] = $data['type_id'];
                    $bn[$k] = $data['bn'];
                    $name[$k] = $data['name'];
                    $sale_price[$k] = $data['sale_price'];
                    $sale_num[$k] = $data['sale_num'];
                    $sale_amount[$k] = $data['sale_amount'];
                    $day_amount[$k] = $data['day_amount'];
                    $day_num[$k] = $data['day_num'];
                    $reship_num[$k] = $data['reship_num'];
                    $reship_ratio[$k] = $data['reship_ratio'];
                    $reship_total_amount[$k] = $data['reship_total_amount'];
                    $agv_cost_amount[$k] = $data['agv_cost_amount'];
                    $cost_amount[$k] = $data['cost_amount'];
                    $agv_gross_sales[$k] = $data['agv_gross_sales'];
                    $gross_sales[$k] = $data['gross_sales'];
                    $gross_sales_rate[$k] = $data['gross_sales_rate'];
                    $cat_id[$k] = $data['cat_id'];
                }

                if(is_string($orderType)){
                    $arr = explode(" ", $orderType);
                    if(strtolower($arr[1]) == 'desc'){
                        array_multisort(${$arr[0]},SORT_DESC,$rows);
                    }
                    else{
                        array_multisort(${$arr[0]},SORT_ASC,$rows);
                    }
                }
             }
        }

        return $rows;
    }

    public function rfilter($filter){
        $where = array(1);
        #店铺
        if(isset($filter['shop_id']) && $filter['shop_id']){
            $where[] = ' sa.shop_id =\''.addslashes($filter['shop_id']).'\'';
        }

        if(isset($filter['time_from']) && $filter['time_from']){
            $where[] = ' S.ship_time >='.strtotime($filter['time_from']);
        }

        if(isset($filter['time_to']) && $filter['time_to']){
            $where[] = ' S.ship_time <'.strtotime($filter['time_to']);
        }

        $where[] = ' sai.return_type = "return"';
        return implode($where,' AND ');
    }

    public function _filter($filter,$tableAlias=null,$baseWhere=null){
        $config = app::get('eccommon')->getConf('analysis_config');

        $filter['order_status'] = $config['filter']['order_status'];
        $where = array(1);
        $itemsid = array();

        #店铺
        if(isset($filter['shop_id']) && $filter['shop_id']){
            $where[] = ' S.shop_id =\''.addslashes($filter['shop_id']).'\'';
        }

        #货号
        if(isset($filter['bn']) && $filter['bn']){
            $where[] = ' SI.bn LIKE \''.addslashes($filter['bn']).'%\'';
            $_SESSION['bn'] = $filter['bn'];
        }else{
            unset($_SESSION['bn']);
        }

        if(isset($filter['order_status']) && $filter['order_status']){
            switch($filter['order_status']){
                case 'createorder':
                    $time_filter = 'order_create_time';
                break;
                case 'confirmed':
                    $time_filter = 'order_check_time';
                break;
                case 'pay':
                    $time_filter = 'paytime';
                break;
                case 'ship':
                    $time_filter = 'ship_time';
                break;
            }

            if(isset($filter['time_from']) && $filter['time_from']){
                $time_from = ' S.'.$time_filter.' >='.strtotime($filter['time_from']);
                $where[] = $time_from;
                $ftime = $time_from;
            }

            if(isset($filter['time_to']) && $filter['time_to']){

                $time_to = ' S.'.$time_filter.' <'.strtotime($filter['time_to']);
                $where[] = $time_to;
                $ftime .= ' AND '.$time_to;
            }
        }else{
            $config['filter']['order_status'] = 'ship';
            app::get('eccommon')->setConf('analysis_config', $config);
            $time_filter = 'ship_time';
        }

        #查询销售额
        if(isset($filter['_sale_amount_search']) && is_numeric($filter['sale_amount'])){
            switch ($filter['_sale_amount_search']){
                case 'than': $_sql =   ' group by SI.bn HAVING  sale_amount >'.$filter['sale_amount'];break;
                case 'lthan': $_sql =  ' group by SI.bn HAVING  sale_amount <'.$filter['sale_amount'];break;
                case 'nequal': $_sql = ' group by SI.bn HAVING  sale_amount ='.$filter['sale_amount'];break;
                case 'sthan': $_sql =  ' group by SI.bn HAVING  sale_amount <='.$filter['sale_amount'];break;
                case 'bthan': $_sql =  ' group by SI.bn HAVING  sale_amount >='.$filter['sale_amount'];break;
                case 'between':
                    if($filter['sale_amount_from'] && $filter['sale_amount_to'] ){
                        $_sql = ' group by SI.bn HAVING  (sale_amount  >='.$filter['sale_amount_from'].' and sale_amount < '.$filter['sale_amount_to'].')';
                    }else{
                        $_sql = '';
                    }
                    break;
            }
        }

        #查询销售量
        if(isset($filter['_sale_num_search']) && is_numeric($filter['sale_num'])){
            if(isset($filter['_sale_amount_search']) && is_numeric($filter['sale_amount'])){
                $_sql = $_sql.' and ';
            }else{
                $_sql = ' group by SI.bn HAVING ';
            }
            switch ($filter['_sale_num_search']){
                case 'than': $_sql =   $_sql.' sale_num >'.$filter['sale_num'];break;
                case 'lthan': $_sql =  $_sql.' sale_num <'.$filter['sale_num'];break;
                case 'nequal': $_sql = $_sql.' sale_num ='.$filter['sale_num'];break;
                case 'sthan': $_sql =  $_sql.' sale_num <='.$filter['sale_num'];break;
                case 'bthan': $_sql =  $_sql.' sale_num >='.$filter['sale_num'];break;
                case 'between':
                    if($filter['sale_num_from'] && $filter['sale_num_to'] ){
                        $_sql = $_sql.'(sale_num  >='.$filter['sale_num_from'].' and sale_num < '.$filter['sale_num_to'].')';
                    }else{
                        $_sql = '';
                    }
                 break;
             }
         }

        if($where){
            $basefilter = implode($where,' AND ');    
            if($_sql){
                $basefilter = $basefilter.' '.$_sql;
                return $basefilter;
            }else{
                return $basefilter;
            }
        }
    }

    public function get_schema(){
        $schema = array (
            'columns' => array (
                'type_id' => array (
                    'type' => 'varchar(50)',
                    'label' => '属性',
                    'width' => 110,
                    'editable' => false,
                    'in_list' => true,
                    'default_in_list' => true,
                    'order'=>1,
                    'orderby' => true,
                    'realtype' => 'varchar(200)',
                ),
                'bn' => array (
                    'type' => 'varchar(50)',
                    'required' => true,
                    'default' => 0,
                    'label' => '基础物料编码',
                    'width' => 120,
                    'searchtype' => 'has',
                    'editable' => true,
                    'filtertype' => 'bool',
                    'filterdefault' => 'true',
                    'in_list' => true,
                    'default_in_list' => true,
                    'orderby' => true,
                    'order'=>4,
                    'realtype' => 'varchar(50)',
                ),
                'name' => array (
                    'type' => 'varchar(200)',
                    'pkey' => true,
                    'label' => '基础物料名称',
                    'width' => 310,
                    #'searchtype' => 'has',
                    'editable' => false,
                    'in_list' => true,
                    'orderby' => true,
                    'default_in_list' => true,
                    'order'=>5,
                    'realtype' => 'varchar(200)',
                ),
                'sale_price' => array (
                    'type' => 'money',
                    'default' => 0,
                    'required' => true,
                    'label' => '销售单价',
                    'width' => 110,
                    'editable' => false,
                    //'filtertype' => 'number',
                    'in_list' => true,
                    'default_in_list' => true,
                    'orderby' => true,
                    'order'=>7,
                    'realtype' => 'mediumint(8) unsigned',
                ),
                'sale_num' => array (
                    'type' => 'number',
                    'label' => '销售量',
                    'width' => 75,
                    'editable' => true,
                    'filtertype' => 'normal',
                    'filterdefault' => 'true',
                    'in_list' => true,
                    'is_title' => true,
                    'default_in_list' => true,
                    'orderby' => true,
                    'order'=>8,
                    'realtype' => 'mediumint(8) unsigned',
                ),
                'sale_amount' => array (
                    'type' => 'money',
                    'default' => 0,
                    'required' => true,
                    'label' => '销售额',
                    'width' => 110,
                    'orderby' => true,
                    'editable' => false,
                    'filtertype' => 'number',
                    'filterdefault' => 'true',
                    'in_list' => true,
                    'default_in_list' => true,
                    'order'=>9,
                    'realtype' => 'mediumint(8) unsigned',
                ),
                'day_amount' => array (
                    'type' => 'money',
                    'default' => 0,
                    'required' => true,
                    'label' => '日均销售额',
                    'width' => 110,
                    'orderby' => true,
                    'editable' => false,
                    //'filtertype' => 'number',
                    'in_list' => true,
                    'default_in_list' => true,
                    'order'=>10,
                    'realtype' => 'mediumint(8) unsigned',
                ),
                'day_num' => array (
                    'type' => 'number',
                    'label' => '日均销售量',
                    'width' => 75,
                    'orderby' => true,
                    'editable' => true,
                    //'filtertype' => 'normal',
                    //'filterdefault' => 'true',
                    'in_list' => true,
                    'is_title' => true,
                    'default_in_list' => true,
                    'order'=>11,
                    'realtype' => 'mediumint(8) unsigned',
                ),
                'reship_num' => array (
                    'type' => 'varchar(200)',
                    'default' => 1,
                    'required' => true,
                    'label' => '退货量',
                    'orderby' => true,
                    'width' => 110,
                    'editable' => true,
                    //'filtertype' => 'yes',
                    'in_list' => true,
                    'default_in_list' => true,
                    'order'=>12,
                    'realtype' => 'mediumint(8) unsigned',
                ),
                'reship_ratio' => array (
                    'type' => 'varchar(200)',
                    'label' => '退货率',
                    'width' => 110,
                    'orderby' => false,
                    'editable' => false,
                    //'filtertype' => 'time',
                    //'filterdefault' => true,
                    'in_list' => true,
                    'default_in_list' => true,
                    'order'=>13,
                    'realtype' => 'varchar(50)',
                ),
                'reship_total_amount' => array (
                    'type' => 'money',
                    'default' => 1,
                    'required' => true,
                    'label' => '退货总额',
                    'orderby' => true,
                    'width' => 110,
                    'editable' => true,
                   // 'filtertype' => 'yes',
                    'in_list' => true,
                    'default_in_list' => true,
                    'order'=>14,
                    'realtype' => 'mediumint(8) unsigned',
                ),
                'agv_cost_amount' => array (
                    'type' => 'money',
                    'default' => 0,
                    'required' => true,
                    'label' => '平均成本',
                    'width' => 110,
                    'orderby' => true,
                    'editable' => false,
                    //'filtertype' => 'number',
                    'in_list' => true,
                    'default_in_list' => true,
                    'order'=>15,
                    'realtype' => 'mediumint(8) unsigned',
                ),
                'cost_amount' => array (
                    'type' => 'money',
                    'default' => 0,
                    'required' => true,
                    'label' => '销售成本',
                    'width' => 110,
                    'orderby' => true,
                    'editable' => false,
                    //'filtertype' => 'number',
                    'in_list' => true,
                    'default_in_list' => true,
                    'order'=>16,
                    'realtype' => 'mediumint(8) unsigned',
                ),
                'agv_gross_sales' => array (
                    'type' => 'money',
                    'default' => 0,
                    'required' => true,
                    'label' => '销售平均毛利',
                    'width' => 110,
                    'orderby' => true,
                    'editable' => false,
                   // 'filtertype' => 'number',
                    'in_list' => true,
                    'default_in_list' => true,
                    'order'=>17,
                    'realtype' => 'mediumint(8) unsigned',
                ),
                'gross_sales' => array (
                    'type' => 'money',
                    'default' => 0,
                    'required' => true,
                    'label' => '销售毛利',
                    'width' => 110,
                    'orderby' => true,
                    'editable' => false,
                    //'filtertype' => 'number',
                    'in_list' => true,
                    'default_in_list' => true,
                    'order'=>18,
                    'realtype' => 'mediumint(8) unsigned',
                ),
                'gross_sales_rate' => array (
                    'type' => 'varchar(200)',
                    'default' => 0,
                    'required' => true,
                    'label' => '销售毛利率',
                    'width' => 110,
                    'orderby' => false,
                    'editable' => false,
                    //'filtertype' => 'number',
                    'in_list' => true,
                    'default_in_list' => true,
                    'order'=>19,
                    'realtype' => 'mediumint(8) unsigned',
                ),
                'total_cost_amount' => array (
                    'type' => 'money',
                    'default' => 1,
                    'required' => true,
                    'label' => '总成本',
                    'orderby' => true,
                    'width' => 110,
                    'editable' => true,
                    //'filtertype' => 'yes',
                    'in_list' => true,
                    'default_in_list' => true,
                    'order'=>20,
                    'realtype' => 'mediumint(8) unsigned',
                ),
                'total_gross_sales' => array (
                    'type' => 'money',
                    'default' => 1,
                    'required' => true,
                    'label' => '总毛利',
                    'orderby' => true,
                    'width' => 110,
                    'editable' => true,
                   // 'filtertype' => 'yes',
                    'in_list' => true,
                    'default_in_list' => true,
                    'order'=>21,
                    'realtype' => 'mediumint(8) unsigned',
                ),
                'total_gross_sales_rate' => array (
                    'type' => 'varchar(200)',
                    'default' => 0,
                    'required' => true,
                    'label' => '总毛利率',
                    'width' => 110,
                    'orderby' => false,
                    'editable' => false,
                    //'filtertype' => 'number',
                    'in_list' => true,
                    'default_in_list' => true,
                    'order'=>22,
                    'realtype' => 'mediumint(8) unsigned',
                ),
                'cat_id' => array (
                    'type' => 'varchar(200)',
                    'default' => 0,
                    'required' => true,
                    'label' => '物料类型',
                    'width' => 110,
                    'orderby' => false,
                    'editable' => false,
                    //'filtertype' => 'number',
                    'in_list' => true,
                    'default_in_list' => true,
                    'order'=>23,
                    'realtype' => 'mediumint(8) unsigned',
                ),
            ),
            'idColumn' => 'bn',
            'in_list' => array (
                0 => 'type_id',
                //1 => 'brand',
                //2 => 'goods_bn',
                3 => 'bn',
                4 => 'name',
                //5 => 'goods_specinfo',
                6 => 'sale_price',
                7 => 'sale_num',
                8 => 'sale_amount',
                9 => 'day_amount',
                10 => 'day_num',
                11 => 'reship_num',
                12 => 'reship_ratio',
                13 => 'reship_total_amount',
                14 => 'agv_cost_amount',
                15 => 'cost_amount',
                16 => 'agv_gross_sales',
                17 => 'gross_sales',
                18 => 'gross_sales_rate',
                19 => 'cat_id',
            ),
            'default_in_list' => array (
                0 => 'type_id',
                //1 => 'brand',
                //2 => 'goods_bn',
                3 => 'bn',
                4 => 'name',
                //5 => 'goods_specinfo',
                6 => 'sale_price',
                7 => 'sale_num',
                8 => 'sale_amount',
                9 => 'day_amount',
                10 => 'day_num',
                11 => 'reship_num',
                12 => 'reship_ratio',
                13 => 'reship_total_amount',
                14 => 'agv_cost_amount',
                15 => 'cost_amount',
                16 => 'agv_gross_sales',
                17 => 'gross_sales',
                18 => 'gross_sales_rate',
                19 => 'cat_id',
            ),
        );
        return $schema;
    }

    /**
     * 获得日志类型(non-PHPdoc)
     * @see dbeav_model::getLogType()
     */
    public function getLogType($logParams) {
        $type = $logParams['type'];
        $logType = 'none';
        if ($type == 'export') {
            $logType = $this->exportLogType($logParams);
        }
        elseif ($type == 'import') {
            $logType = $this->importLogType($logParams);
        }
        return $logType;
    }
    /**
     * 导出日志类型
     * @param Array $logParams 日志参数
     */
    public function exportLogType($logParams) {
        $params = $logParams['params'];
        $type = 'report';
        if ($logParams['app'] == 'omeanalysts' && $logParams['ctl'] == 'ome_analysis') {
            $type .= '_salesReport_posSales';
        }
        $type .= '_export';
        return $type;
    }
    /**
     * 导入操作日志类型
     * @param Array $logParams 日志参数
     */
    public function importLogType($logParams) {
        $params = $logParams['params'];
        $type = 'report';
        if ($logParams['app'] == 'omeanalysts' && $logParams['ctl'] == 'ome_analysis') {
            $type .= '_salesReport_posSales';
        }
        $type .= '_import';
        return $type;
    }

    //根据查询条件获取导出数据
    public function getExportDataByCustom($fields, $filter, $has_detail, $curr_sheet, $start, $end){
        //根据选择的字段定义导出的第一行标题
        if($curr_sheet == 1){
            $data['content']['main'][] = $this->getExportTitle($fields);
        }

        $productssale = $this->getList('*',$filter,$start,$end);
        if(!$productssale) return false;
        
        foreach ($productssale as $k => $aFilter) {
            $exptmp_data = array();
            foreach (explode(',', $fields) as $key => $col) {
                if(isset($aFilter[$col])){
                    $aFilter[$col] = mb_convert_encoding($aFilter[$col], 'GBK', 'UTF-8');
                    $exptmp_data[] = $aFilter[$col];
                }
                else
                {
                    $exptmp_data[]    = '';
                }
            }

            $data['content']['main'][] = implode(',', $exptmp_data);
        }

        return $data;
    }

}